package misc;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Dimension;
import static javax.swing.GroupLayout.Alignment.*;

public class TestSwing {
	static JFrame jf;
	static JPanel jp;
	static JButton jb;
	static GroupLayout layout;
	public static void main(String[] args) {
		
		jp = new JPanel();
		jp.setPreferredSize(new Dimension(500,500));
		jp.setBorder(BorderFactory.createTitledBorder("Panel Area"));
		
		jb = new JButton("Hello World");
		jb.addActionListener(
				new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						System.out.println("Button clicked.");
					}
				}
		);
		
		jf = new JFrame();
		layout = new GroupLayout(jf.getContentPane());
		jf.getContentPane().setLayout(layout);
		layout.setAutoCreateGaps(true);
		layout.setAutoCreateContainerGaps(true);
		layout.setHorizontalGroup(layout.createSequentialGroup()
				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
						.addComponent(jp)
						.addComponent(jb)
				));
		layout.setVerticalGroup(
				layout.createSequentialGroup()
				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
					.addComponent(jp))
				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
					.addComponent(jb))
				);
		
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf.add(jb);
		jf.add(jp);
		jf.pack();
		jf.setVisible(true);
	}

}
